#include "msp430g2231.h"

int S1,S2 ;
s1=0;
S2=0;

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled
  ADC10CTL1 = INCH_4;                       // input A1//
  ADC10AE0 |= 1<<4;                         // PA.1 ADC option select
  P1DIR |= 0x01;                            // Set P1.0 to output direction

  for (;;)
  {
    ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start
    __bis_SR_register(CPUOFF + GIE);        // LPM0, ADC10_ISR will force exit
    if (ADC10MEM >  0x1FF)                    //1FF=511 //
      P1OUT &= ~0x01;                       // Clear P1.0 LED off
    else
      P1OUT |= 0x01;                        // Set P1.0 LED on
  }
    if ((0x8 & P1IN)&&(s1>0))
	{
	s1++;
	P1OUT = 0x01;
        }
    else
	{
	P1OUT &= ~0x01;
	}
    if ((0x9 & P1IN)&&(s1>0))
	{
	s2++;
	P1OUT = 0x01;	
        }
    else
	{
	P1OUT &= ~0x01;	

	}
}

// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__attribute__((interrupt(TIMERA0_VECTOR))) void Timer_A (void)
{
  __bic_SR_register_on_exit(CPUOFF);        // Clear CPUOFF bit from 0(SR)
}
//P1.0=VCC
//P1.4 = X ^
//P1.5 = Y <-
//P1.6 = Z .
//P1.8 = RST(S1)
//fi   = arctan(Y/Z)
//psi  = arctan(Y/X)
//tetta= arctan(X/Z)
 
